<!DOCTYPE html>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<script src="js/cashier_mana/jquery.service.spa_init_sellte_account.js"></script>
		<script src="js/plugin/jsonsql.js"></script>
		
		<link rel="stylesheet" href="css/cashier_mana/ledger.css"/>
	</head>
	<body> 
			<div id="settleAccounts">
				<div class="widget-box">
					<div class="widget-body">
						<div class="widget-box" style="margin:0px;">
							<div id="ledgerHeader" class="widget-body hide"></div>  
							<div id="frontPosMessInfo"></div> 
						</div>
						<div id="posorderBill">
							<div class="widget-box" style="margin:0px;display:flex;">
								<div id="connectList" class="widget-body" style="width:0%;">
									
								</div>
								<div id="billList" class="widget-body" style="overflow-y:auto;width:100%;border-left:1px solid #cccccc;">
									<div class="tableMoney">
										<div class="money_top"> 
											<div class="money_left_info"></div>
											<table class="table table-striped table-bordered" style="border:0;"> 
												<tbody id="tableMethodTable" style="font-size:16px;">                   
													
												</tbody>    
											</table> 
										</div>	
										<div class="pay_price"  style="font-size:25px">
											<label style="font-size:25px" data-i18n="应收:"></label>
											<span class="pay_p">￥0.00</span>
										</div>   
									</div>
								</div>
							</div>
							<div id="jzBtnContent" class="money_center" style="position:relative;">
							</div>
						</div>
					</div> 
				</div>
				<div class="hide">
			   		<div id="errorContentDiv"></div>
				</div>
			</div>  
		
		
		<script src="assets/i18n/i18nReplace.js"></script>
		<script type="text/javascript">
			var jdh=$(document).data("jdh");
		    var no=$(document).data("no");
		    var nos=$(document).data("nos");
		    var nos_checkout=$(document).data("nos_checkout");
		    var mno=$(document).data("mno");
		    var th=$(document).data("th");
		    var bmh=$(document).data("bmh");
		    var operation=$(document).data("operation");
		    document.title = $.i18n.propJsp("前台收银");
			var payment = $.parseJSON(localStorage.getItem("payment"))
			var ho_dcode = $.parseJSON(localStorage.getItem("ho_dcode"))
			var xhs = $(document).data("xhs")
			
			function getData(condition){
				var arg = {}
				if(condition){
					arg = condition
				}else{
					arg = {"arg":{"no":no,"operation":operation,"nos":nos,"nos_checkout":nos_checkout}}
					if(operation=="选择结账"){
						arg.arg.xhs = $(document).data("xhs")
					}
				}
				
				jQuery.ajax({  
		    		type : 'POST',
		    		url : $.HSAPI_AJAXURL+"/qms/mobile/procedure2",
		    		data : $.HSAPI_ASKJSONINFO(JSON.stringify(arg),'SPAOrderPayment_Checkout_Before','{}'), 
		    		dataType : 'json',  
		    		success : function(data){
		    			if(data.RETURN==1){
// 		    				console.log(JSON.stringify(data));       
		    				initSettleAccounts(data); 
		    			}else if(data.RETURN=="-10"){ 
    						errorContent(arg,data);  
    					}else if(data.RETURN=="-11"){ 
    						errorContent_11(arg,data);  
    					}else{
							if(data.hasOwnProperty("gritter")){
								if(data.hasOwnProperty("gritterstyle"))
									jf_successDelayed(data.gritter,2000,data.gritterstyle);
								else
									jf_successDelayed(data.gritter,2000); 
							}else{
			    				jf_alert(data.MSG)
							}
						}
		    		},  
		    		error : function(data){
		    			jf_alert(JSON.stringify(data));
		    		}  
		    	});
			}
			getData();
			
			function initSettleAccounts(data){
				$("#tableMethodTable").empty();
				
				$(data.settleamount).each(function(key,value){ 
					var name = ""
					$.each(JSON.parse(value.name),function(k,v){
						var extendCss = "margin-right:2px;"
						name += getTextStyle(v,extendCss)
					})
					var html='<tr>'+  
								'<td class="center;" style="border: 0px;width:200px;">'+name+'</td>'+  
								'<td class="left;" style="border: 0px;">'+value.info+'</td>'+  
								'<td style="text-align:right;border: 0px;width:200px;">'+value.amount+'</td>'+         
							'</tr>';
					$("#tableMethodTable").append(html); 
				});
				$(".pay_p").text("￥"+ data.total);
				
				$("#settleAccounts").spa_init_sellte_account("initJzType",{
					operation:operation,
					"width":$("#settleAccounts").width(),
					"payment":payment,
					"ho_dcode" : ho_dcode,
					brzd_array : ins_argjson.brzd_array,
					pageTh:th,
					mno : mno,
					bmh : bmh,
					xhs : xhs,
					"amount":{
// 						"balance":Number(data.amount)
						"balance":Number(data.total)
					},
					"togatherPrice":nos.split(",").length==1?0:Number(data.together),
					"nos":nos.split(",").length==1?"":nos,
					"nos_checkout":nos_checkout,
					"ct_brzd":{
						"no":no
					},
					dataBack : function(oper){
						refreshTh(jdh);
						$("#selectTable").trigger("click")
					},
					closeBack : function(){  
						searchByBh(th);
						$("#selectTable").trigger("click")
					},
					refreshBack : function(){
						searchByBh(th);
						getData();
					},
				});
			}
			
			function refreshTh(jdh){
				searchByBh(undefined,function(){
					$("#btnShowFtp").trigger("click");
				},jdh);
			}
			
			function setSize(){
				var winh = $(window).height();
				var top = $("#posorderBill").offset().top;  
				var h = winh - top-178;     
				$("#billList").css({"height":$("#settleAccounts").parent().height()-110}); 
				$("#settleAccounts").parent().removeClass("hide"); 
				$("#settleAccounts").spa_init_sellte_account("initJzType",{"width":$("#settleAccounts").width(),"payment":payment,"ho_dcode" : ho_dcode}); 
			}
			
			//出错提示
	    	function errorContent(pa,data){
	    		var MSG = data.MSG;
	    		var name = data.checkbox;
	    		
	    		var html = 	'<h3 class="header smaller lighter blue">'+
	    						'<i class="ace-icon fa fa-bullhorn"></i>'+MSG+
	    					'</h3>'+
	    					'<div class="alert alert-block alert-danger">'+
	    						'<label>'+
	    							'<input id="checkin_cccheckbox" type="checkbox" name="'+name+'" value="" class="ace"/>'+ 
	    							'<span class="lbl" style="color:#478fca;">'+MSG+'</span>'+
	    						'</label>'+
	    					'</div>';

	    		bootbox.dialog({
	    			message: html,
	    			buttons:{
	    				"button1":{
	    					"label" : $.i18n.propJsp("确定"),
	    					"className" : "btn-sm btn-info",
	    					"callback" : function(){
	    						if($("#checkin_cccheckbox").prop("checked")){
	    							pa.arg[name]="yes";
	    						}else{
	    							pa.arg[name]="no";
	    						}
	    						getData(pa)
	    					}
	    				},	
	    				"button" :
	    				{
	    					"label" : $.i18n.propJsp("取消"),
	    					"className" : "btn-sm",
	    				},
	    			}
	    		});
	    	}
	    	//出错提示-11
	    	function errorContent_11(pa,data){
	    		var name = data.radiobutton
	    		
	    		$("#errorContentDiv").modalFrame("destroy");
				$("#errorContentDiv").modalFrame("init",function(modalEle){
					if(!$.isFunction($().RETURN_11)){
						$.ajaxSetup({ async: false, cache: false });
			            $.getScript("js/cashier_mana/jquery.RETURN_11.js");
			            $.ajaxSetup({ async: true });
					}
			    	$("#"+modalEle).RETURN_11({
			    		data:data,
			    		dataBack : function(data){
			    			$("#"+modalEle).modal("hide");
			    			$("#"+modalEle).empty();
			    			pa.arg[name]=data;
			    			getData(pa)
			    		},
			    		returnBack : function(){
			    			$("#"+modalEle).modal("hide");
			    			$("#"+modalEle).empty();
			    			getData(pa)
			    		},
			    	});
				})
	    					
	    	}
			setSize();
		</script>
	</body>
</html>